package edu.student.models;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import com.util.DB;
/**
Author: Satya Deepthi Bhagi
 **/
public class Announcements {

	private String announcementName;
	

	
	public String getAnnouncementName() {
		return announcementName;
	}


	public void setAnnouncementName(String announcementName) {
		this.announcementName = announcementName;
	}


	

	public static ArrayList<Announcements> getAnnouncements(String selectionModifier) {
		ArrayList<Announcements> selection = new ArrayList<Announcements>();
		ResultSet resultSet = null;
		String query = "select announcement_NAME from announcement a,interest i,user_interests ui " + selectionModifier +" and a.interest_id=i.interest_id and i.interest_id= ui.interest_id and a.duration>=sysdate()";
		Connection connection = DB.getConnection();
		resultSet = DB.readFromDB(query, connection);
		try {
			while (resultSet.next()) {
				Announcements announcement = new Announcements();
				announcement.announcementName=resultSet.getString("announcement_NAME");
				selection.add(announcement);	
			}
		} catch (SQLException e) {
	       System.out.println("Exception while reading from db"+ e);
		}
		DB.close(connection);
		return selection;
	}
}
